package e

import "fmt"

// Resp 返回模板
type Resp struct {
	Status  int         `json:"status"`
	Message string      `json:"msg"`
	Data    interface{} `json:"data,omitempty"`
}

func New(k int) *Resp {
	if val, ok := errCodeMsgFlags[k]; ok {
		return &Resp{Status: k, Message: val}
	}
	return &Resp{Status: ErrNotFound, Message: errCodeMsgFlags[ErrNotFound]}
}

func (r *Resp) AddMessage(message string) *Resp {
	r.Message += " " + message
	return r
}

func (r *Resp) AddMessageF(format string, args ...interface{}) *Resp {
	r.Message += " " + fmt.Sprintf(format, args...)
	return r
}

func (r *Resp) SetMessage(message string) *Resp {
	r.Message = message
	return r
}

func (r *Resp) SetMessageF(args ...interface{}) *Resp {
	r.Message = fmt.Sprintf(r.Message, args...)
	return r
}

func (r *Resp) SetData(data interface{}) *Resp {
	r.Data = data
	return r
}
